import { FG } from "./req"
export const reqSearchUser = (obj = { search: String | Number, page: Number | null }) => {
  return FG.post({
    url: "/searchuser",
    data: {
      ...obj
    }
  })
}
const reqRelation = (obj = { uid: String, fid: Array }) => {
  let reqList = []
  obj.fid.forEach((item) => {
    reqList.push(FG.post({
      url: "/checkstatus",
      data: {
        uid: obj.uid,
        fid: item
      }
    }))
  })
  return Promise.allSettled(reqList)
}

export async function reqRelationEnd(obj = { uid: String, fid: Array }) {
  let res = await reqRelation({ uid: obj.uid, fid: obj.fid })
  let reqErrIndex = []
  res.forEach((item, index) => {
    if (item.status == "rejected") {
      reqErrIndex.push(index)
    }
  })
  let resback = []
  res.forEach(item => {
    resback.push(item.value)
  })
  return {
    res: resback,
    reqErrIndex
  }
}